<?php
include "secretiki.php";

if ( isset($_GET['id']) ) {
	$query = "SELECT * FROM tovars WHERE id=" . $_GET['id'];

	$req = mysqli_query($connection, $query);
	$current_course = mysqli_fetch_assoc($req);
	// var_dump($current_course);

	if (empty($current_course)) {
		header("Location: 404.php");
	}
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="author" content="Roman Shangin">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
    <title>Асик - сервисный центр</title>
    <!-- Fevicon -->
    <link rel="shortcut icon" href="assets/images/favicon.ico">
    <!-- Start css -->
    <!-- Switchery css -->
    <link href="index/assets/plugins/switchery/switchery.min.css" rel="stylesheet">
    <!-- Range Slider css -->
    <link href="index/assets/plugins/ion-rangeSlider/ion.rangeSlider.css" rel="stylesheet" type="text/css">
    <link href="index/assets/css/bootstrap.min.css" rel="stylesheet" type="text/css">
    <link href="index/assets/css/icons.css" rel="stylesheet" type="text/css">
    <link href="index/assets/css/flag-icon.min.css" rel="stylesheet" type="text/css">
    <link href="index/assets/css/style.css" rel="stylesheet" type="text/css">
    
    <link href="components/jquery-ui/jquery-ui.min.css" rel="stylesheet" type="text/css">
    <!-- End css -->
</head>

<body data-page="catalogDB" class="horizontal-layout">
    <!-- Start Containerbar -->
    <div id="containerbar" class="container-fluid">
        <!-- Start Rightbar -->
        <div class="rightbar">
            <!-- Start Topbar Mobile -->
            <div class="topbar-mobile">
                <div class="row align-items-center">
                    <div class="col-md-12">
                        <div class="mobile-logobar">
                            <a href="http://www.asic-irk.xyz/" class="mobile-logo"><img src="assets/images/logo.png" class="img-fluid" alt="logo"></a>
                        </div>
                        <div class="mobile-togglebar">
                            <ul class="list-inline mb-0">
                                <li class="list-inline-item">
                                    <div class="topbar-toggle-icon">
                                        <a class="topbar-toggle-hamburger" href="javascript:void();">
                                            <img src="assets/images/svg-icon/horizontal.svg" class="img-fluid menu-hamburger-horizontal" alt="horizontal">
                                            <img src="assets/images/svg-icon/verticle.svg" class="img-fluid menu-hamburger-vertical" alt="verticle">
                                         </a>
                                     </div>
                                </li>
                                <li class="list-inline-item">
                                    <div class="menubar">
                                        <a class="menu-hamburger navbar-toggle bg-transparent" href="javascript:void();" data-toggle="collapse" data-target="#navbar-menu" aria-expanded="true">
                                            <img src="assets/images/svg-icon/collapse.svg" class="img-fluid menu-hamburger-collapse" alt="collapse">
                                            <img src="assets/images/svg-icon/close.svg" class="img-fluid menu-hamburger-close" alt="close">
                                        </a>
                                     </div>
                                </li>                                
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
            <!-- Start Topbar -->
            <div class="topbar">
                <!-- Start container-fluid -->
                <div class="container-fluid">
                    <!-- Start row -->
                    <div class="row align-items-center">
                        <!-- Start col -->
                        <div class="col-md-12 align-self-center">
                            <div class="togglebar">
                                <ul class="list-inline mb-0">
                                    <li class="list-inline-item">
                                        <div style="padding-top: 12px;" class="logobar">
                                            <a href="http://www.asic-irk.xyz/" class="logo logo-large"><img src="assets/images/logo.png" class="img-fluid" alt="logo"></a>
                                        </div>
                                    </li>
                                </ul>
                            </div>
                            <div class="infobar">
                                <ul class="list-inline mb-0">
                                    <li class="badge list-inline-item" id="total-cart-count" style="width: 0px;padding-right: 0px;">
                                    </li>
                                    <li class="list-inline-item">
                                        <div class="settingbar">
                                            <a href="cart"  class="infobar-icon">
                                                <img src="assets/images/svg-icon/ecommerce.svg" class="img-fluid" alt="settings">
                                            </a>
                                        </div>
                                    </li>
                                    
<style>
.rainbow-animated {
  background: linear-gradient(to right, red, orange, yellow, green, cyan, blue, violet);
  background-size: 400% 400%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  -webkit-animation: rainbow 20s ease infinite;
  animation: rainbow 20s ease infinite;
  font-size: 14px;
  line-height: 25px;
}
 
@-webkit-keyframes rainbow {
  0% { background-position: 0% 50% }
  50% { background-position: 100% 50% }
  100% { background-position: 0% 50% }
}
 
@keyframes rainbow {
  0% { background-position: 0% 50% }
  50% { background-position: 100% 50% }
  100% { background-position: 0% 50% }
}


   .round {
   width: 141px; height: 28px; /* Ширина и высота */
   border-radius: 50%; /* Превращаем в круг */
   }

</style>       


                                    
                                    <li class="list-inline-item">
                                        <div class="profilebar">
                                            <div class="dropdown">
                                            <?php if(isset($_SESSION['logged_user'])) : ?>
                                              <a class="dropdown-toggle" href="#" role="button" id="profilelink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><img src="<?php echo "assets/images/$obje->avatar_user"; ?>" class="round img-fluid" alt="profile"><span class="feather icon-chevron-down live-icon"></span></a>
                                              <?php else : ?>
                                              <a class="dropdown-toggle" href="#" role="button" id="profilelink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><img src="<?php echo "assets/images/users/profile.svg"; ?>" class="round img-fluid" alt="profile"><span class="feather icon-chevron-down live-icon"></span></a>
                                              <?php endif; ?>
                                                <div class="dropdown-menu dropdown-menu-right" aria-labelledby="profilelink">
                                                    <div class="dropdown-item">
                                                        <div class="profilename">
                                        <?php if(isset($_SESSION['logged_user'])) : ?>
                                                 <?php	if ($role == 'Администратор') :?>
                                                          <h5 class="rainbow-animated">Администратор</h5>
                                                 <?php else : ?>
                                                        <?php	if ($role == 'Сотрудник') :?>
                                                        <h5>Сотрудник</h5>
                                                        <?php else : ?>
                                                        <h5><?php echo $_SESSION['logged_user']->name; ?></h5>
                                                        <?php endif; ?>
                                                 <?php endif; ?>
                                        <?php else : ?>
                                                          <h5>Гость</h5>
                                        <?php endif; ?>        
                                                 
                                                        </div>
                                                    </div>
                                                    <div class="userbox">
                                                        
                                        <?php if(isset($_SESSION['logged_user'])) : ?>
                                        
                                                        <ul class="list-unstyled mb-0">
                                                            <li class="media dropdown-item">
                                                                <a href="account" class="profile-icon"><img src="assets/images/svg-icon/user.svg" class="img-fluid" alt="user">Профиль</a>
                                                            </li>
                                                            <li class="media dropdown-item">
                                                                <a href="logout" class="profile-icon"><img src="assets/images/svg-icon/logout.svg" class="img-fluid" alt="logout">Выйти</a>
                                                            </li>
                                                        </ul>
                                        
                                        <?php else : ?>
                                        
                                                        <ul class="list-unstyled mb-0">
                                                            <li class="media dropdown-item">
                                                                <a href="login" class="profile-icon"><img src="assets/images/svg-icon/user.svg" class="img-fluid" alt="user">Войти</a>
                                                            </li>
                                                        </ul>
                                                        
                                        <?php endif; ?>
                                                        
                                                    </div>
                                                </div>
                                            </div>
                                        </div>                                   
                                    </li>
                                    <li class="list-inline-item menubar-toggle">
                                        <div class="menubar">
                                            <a class="menu-hamburger navbar-toggle bg-transparent" href="javascript:void();" data-toggle="collapse" data-target="#navbar-menu" aria-expanded="true">
                                                <img src="assets/images/svg-icon/collapse.svg" class="img-fluid menu-hamburger-collapse" alt="collapse">
                                                <img src="assets/images/svg-icon/close.svg" class="img-fluid menu-hamburger-close" alt="close">
                                            </a>
                                         </div>
                                    </li>
                                </ul>
                            </div>
                        </div>
                        <!-- End col -->
                    </div> 
                    <!-- End row -->
                </div>
                <!-- End container-fluid -->
            </div>
            <!-- End Topbar -->
            <!-- Start Navigationbar -->
            <div class="navigationbar">
                <!-- Start container-fluid -->
                <div class="container-fluid">
                    <!-- Start Horizontal Nav -->
                    <nav class="horizontal-nav mobile-navbar fixed-navbar">
                        <div class="collapse navbar-collapse" id="navbar-menu">
                          <ul class="horizontal-menu">
                            <li>
                                <a href="http://www.asic-irk.xyz/"><img src="assets/images/svg-icon/dashboard.svg" class="img-fluid" alt="dashboard"><span>Главная</span></a>
                            </li>
                            <li>
                                <a href="shop"><img src="assets/images/svg-icon/components.svg" class="img-fluid" alt="components"><span>Магазин</span></a>
                            </li>
                            <li>
                                <a href="reviews"><img src="assets/images/svg-icon/apps.svg" class="img-fluid" alt="apps"><span>Отзывы</span></a>
                            </li>
                            <li>
                                <a href="about"><img src="assets/images/svg-icon/pages.svg" class="img-fluid" alt="pages"><span>Контакты</span></a>
                            </li>
                            <?php	if ($role == 'Администратор') :?>
                            <li>
                                <a href="/adm/index"><img src="assets/images/svg-icon/dashboard.svg" class="img-fluid" alt="dashboard"><span>Панель управления ИС</span></a>
                            </li>
                            <?php else : ?>
                            <?php endif; ?> 
                          </ul>
                        </div>
                    </nav>
                    <!-- End Horizontal Nav -->
                </div>
                <!-- End container-fluid -->
            </div>
            <!-- End Navigationbar -->
            <!-- Start Breadcrumbbar -->                    
            <div class="breadcrumbbar" style="padding-top: 0px;padding-right: 0px;padding-bottom: 0px;padding-left: 0px;width: 0px;">
            </div>
            <!-- End Breadcrumbbar -->

            <!-- Start Contentbar -->    
            <div class="contentbar">                
                <!-- Start row -->
                <div class="row">
                    
                    <!-- Start col -->
                    <div class="col-lg-12">
                        <div class="card m-b-30">
                            <div class="card-header">
                                <h5 class="card-title">Редактирование товара: <?php echo $current_course['name_tovar']?></h5>
                            </div>
                            <div class="card-body">
                                    <form enctype="multipart/form-data" class="form-validate" method="post" action="red_photo_shop">
                                            <input type="hidden" name="id" value="<?php echo $current_course['id']?>">
                                    <div class="form-group row">
                                         <label class="col-lg-3 col-form-label" for="val-email">Фото товара <span class="text-danger">*</span></label>
                                         <div class="col-lg-6">
                                         <input class="form-control" name="photo_tovar" type="file" id="formFile">
                                         </div>
                                    </div>
                                    <div class="form-group row">
                                        <label class="col-lg-3 col-form-label"></label>
                                        <div class="col-lg-8">
                                            <button name="do_toq" type="submit" class="btn btn-success">Сохранить</button>
                                        </div>
                                    </div>                                  
                                </form>
                                
                                
  	<?php 
// Создаем переменную для сбора данных от пользователя по методу POST
$data = $_POST;

// Пользователь нажимает на кнопку "Зарегистрировать" и код начинает выполняться
if(isset($data['do_toq'])) {

        // Регистрируем
        // Создаем массив для сбора ошибок
	$errors = array();


         // функция mb_strlen - получает длину строки
        // Если логин будет меньше 5 символов и больше 90, то выйдет ошибка

	// Проверка на уникальность email

	if(empty($errors)) {

		// Все проверено, регистрируем
		// Создаем таблицу users
		$photo_tovar = $_FILES['photo_tovar']['name'];
		$id = $data['id'];
        $user = R::load('tovars', $id);

                // добавляем в таблицу записи
		$user->photo_tovar = $photo_tovar;

        if(move_uploaded_file($_FILES['photo_tovar']['tmp_name'], 'adm/assets/images/' . $photo_tovar)){
    	echo "норм";
        } else{
	    echo "хуита";
        }

		// Сохраняем таблицу
		R::store($user);
        echo '<div style="color: green; "><b>Изображение успешно отредактировано!</b></div><hr>';

	} else {
                // array_shift() извлекает первое значение массива array и возвращает его, сокращая размер array на один элемент. 
		echo '<div style="color: red; "><b>' . array_shift($errors). '</b></div><hr>';
	}
}

?>                                 
                                
                                
                                
                                
                                
                                
                                
                            </div>
                        </div>
                    </div>
                    <!-- End col -->                    
                    
                    
                    
                </div>
                <!-- End row -->
            </div>
            <!-- End Contentbar -->
            <!-- Start Footerbar -->
            <div class="footerbar">
                <footer class="footer">
                    <p class="mb-0">© 2022 Асик - Все права защищены.</p>
                </footer>
            </div>
            <!-- End Footerbar -->
        </div>
        <!-- End Rightbar -->
    </div>
    <!-- End Containerbar -->
    <!-- Start js -->        
    <script src="index/assets/js/jquery.min.js"></script>
    <script src="index/assets/js/popper.min.js"></script>
    <script src="index/assets/js/bootstrap.min.js"></script>
    <script src="index/assets/js/modernizr.min.js"></script>
    <script src="index/assets/js/detect.js"></script>
    <script src="index/assets/js/jquery.slimscroll.js"></script>
    <script src="index/assets/js/horizontal-menu.js"></script>
    <!-- Switchery js -->
    <script src="index/assets/plugins/switchery/switchery.min.js"></script>
    <!-- Range Slider js -->
    <script src="index/assets/plugins/ion-rangeSlider/ion.rangeSlider.min.js"></script>
    <!-- eCommerce Shop Page js -->
    <script src="index/assets/js/custom/custom-ecommerce-shop-page.js"></script>
    <!-- Core js -->
    <script src="index/assets/js/core.js"></script>
    
    <script src="js/vendor/jquery.cookie.js" type="text/javascript"></script>
    <script src="components/jquery-ui/jquery-ui.min.js" type="text/javascript"></script>
    <script src="js/vendor/underscore.min.js" type="text/javascript"></script>
    <script src="js/modules/catalogDB.js" type="text/javascript"></script>
    <script src="js/modules/cart.js" type="text/javascript"></script>
    <script src="js/modules/compare.js" type="text/javascript"></script>
    <script src="js/modules/main.js" type="text/javascript"></script>
    <!-- End js -->
</body>
</html>